package net.kosev.su.tetris;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;

interface Tile {
	public void draw(Graphics2D g, int x, int y, int size, Color color);
}

class SimpleTile implements Tile {

	public void draw(Graphics2D g, int x, int y, int size, Color color) {
		g.setColor(color);
		g.fillRect(x, y, size, size);
	}
	
}

abstract class TileDecorator implements Tile {
	protected Tile decoratedTile;
	
	public TileDecorator(Tile tile) {
		decoratedTile = tile;
	}
	
}

class GlossDecorator extends TileDecorator {

	public GlossDecorator(Tile tile) {
		super(tile);
	}

	public void draw(Graphics2D g, int x, int y, int size, Color color) {
		decoratedTile.draw(g, x, y, size, color);
		if (color != Color.BLACK) {
			drawGloss(g, x, y, size);
		}
	}

	private void drawGloss(Graphics2D g, int x, int y, int size) {
		Polygon p = new Polygon();
		p.addPoint(x + 2, y + 2);
		p.addPoint(x + 7, y + 2);
		p.addPoint(x + 2, y + 7);
		
		g.setColor(new Color(0xFF, 0xFF, 0xFF, 0xAA));
		g.fillPolygon(p);
	}
	
}

class BorderDecorator extends TileDecorator {

	public BorderDecorator(Tile tile) {
		super(tile);
	}

	public void draw(Graphics2D g, int x, int y, int size, Color color) {
		decoratedTile.draw(g, x, y, size, color);
		if (color != Color.BLACK) {
			drawBorder(g, x, y, size);
		}
	}

	private void drawBorder(Graphics2D g, int x, int y, int size) {
		g.setColor(new Color(0xFF, 0xFF, 0xFF, 0x66));
		g.setStroke(new BasicStroke(1));
		g.drawRect(x, y, size - 1, size - 1);
	}
	
}